<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>资料修改</title>
    <#assign base=request.contextPath/>
    <#setting  number_format="0.##"/>
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="${base}/backstage/layui/css/layui.css" media="all">
    <script src="${base}/backstage/layui/layui.js?t=1"></script>
    <script src="${base}/backstage/js/jquery-1.8.3.min.js?t=1"></script>
    <script src="${base}/backstage/js/feng.js?t=1"></script>
    <script src="${base}/backstage/js/loading.js?t=1"></script>
</head>
<body>
<br>
<form class="layui-form " action="" style="padding-left: 15px;">

    <input type="hidden" value="${user.id}" id="id"/>

    <br>
<#--    <div class="layui-upload-drag" id="test10" style="position: relative;left:7%">-->
<#--        <div  id="uploadDemoView">-->
<#--            <#if user.url??>-->
<#--                <img src="${user.url}" style="width: 342px;height: 136px">-->
<#--            <#else>-->
<#--                <img src="${base}/backstage/images/touxiang.jpg" style="width: 342px;height: 136px" class="layui-nav-img">-->
<#--            </#if>-->
<#--        </div>-->
<#--        <i class="layui-icon"></i>-->
<#--        <p>点击上传头像，或将文件拖拽到此处</p>-->
<#--    </div>-->
<#--    <br>-->
<#--    <br>-->


    <div class="layui-form-item">
        <label class="layui-form-label">商家名称</label>
        <div class="layui-input-block">
            <input class="layui-input" value="${user.nameOfMerchant}" name="nameOfMerchant" id="nameOfMerchant" placeholder="请输入商家名称" autocomplete="off">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">商家联系人</label>
        <div class="layui-input-block">
            <input class="layui-input" value="${user.merchantContact}" name="merchantContact" id="merchantContact" placeholder="请输入商家联系人" autocomplete="off">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">联系电话</label>
        <div class="layui-input-block">
            <input class="layui-input" value="${user.phone}" name="phone" id="phone" placeholder="请输入商家联系电话" autocomplete="off">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">商家地址</label>
        <div class="layui-input-block">
            <input class="layui-input" value="${user.address}" name="address" id="address" placeholder="请输入商家地址" autocomplete="off">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">账户</label>
        <div class="layui-input-block">
            <input class="layui-input" name="account" disabled value="${user.account}" id="account" placeholder="请输入账户" autocomplete="off">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-block">
            <input class="layui-input" name="passWord" value="${user.passWord}" id="passWord" placeholder="请输入密码" autocomplete="off">
        </div>
    </div>
    <br>
    <div class="layui-upload" style="position: relative;left:7%">
        <button type="button" class="layui-btn" id="test2">商家门头照</button>
        <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
            预览图：
            <div class="layui-upload-list" id="demo2">
                <#list userImage as userImage>
                    <img src="${userImage.url}" style="width: 264px;height: 136px">
                </#list>
            </div>
        </blockquote>
    </div>


    <div align="center">
        <button type="button" class="layui-btn" id="saveButton">保存</button>
        <button type="button" class="layui-btn" onclick="window.history.back(-1);">返回</button>
    </div>
    <br>
    <br>

</form>
<script>
    var param="";
    var duoImage = "";
    layui.use(['form', 'layer', 'upload'], function () {
        var form = layui.form
            , layer = layui.layer
            , $ = layui.jquery
            , upload = layui.upload;


        //拖拽上传
        <#--upload.render({-->
        <#--    elem: '#test10'-->
        <#--    ,url: '${base}/file/uploadFile' //改成您自己的上传接口-->
        <#--    , before: function (obj) {-->
        <#--        layer.load(); //上传loading-->
        <#--    }-->
        <#--    ,done: function(res){-->
        <#--        layer.closeAll('loading'); //关闭loading-->
        <#--        if (res.code > 0) {-->
        <#--            return layer.msg('上传失败');-->
        <#--        }-->
        <#--        layer.msg('上传成功');-->
        <#--        // layui.$('#uploadDemoView').removeClass('layui-hide').find('img').attr('src', res.files.file);-->
        <#--        $("#uploadDemoView").html("")-->
        <#--        $('#uploadDemoView').append('<div><img src="' + res.data + '" style="width: 342px;height: 136px"></div>'); //图片链接（base64）-->
        <#--        $("#test10 i").remove()-->
        <#--        $("#test10 p").remove()-->
        <#--        param += res.data;-->
        <#--    }-->
        <#--});-->

        //多图片上传
        upload.render({
            elem: '#test2'
            ,url: '${base}/file/uploadFile' //改成您自己的上传接口
            ,multiple: true
            ,before: function(obj){
                layer.load(); //上传loading
                $('#demo2').html("")
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#demo2').append('<img src="'+ result +'" alt="'+ file.name +'" class="layui-upload-img" style="width: 342px;height: 136px">')
                });
            }
            ,done: function(res){
                //上传完毕
                layer.closeAll('loading'); //关闭loading
                if(res.code>0){
                    return layer.msg('上传失败');
                }else{
                    duoImage += res.data+";";
                    return  layer.msg('上传成功');
                }
            }
        });

    })


    $("#saveButton").on("click", function () {

        if ($("#nameOfMerchant").val() == "") {
            layer.msg("商家名称不能为空")
            return;
        }
        if ($("#nameOfMerchant").val().length>4) {
            layer.msg("商家名称不能超过4个字")
            return;
        }
        if ($("#merchantContact").val() == "") {
            layer.msg("商家联系人不能为空")
            return;
        }
        if ($("#phone").val() == "") {
            layer.msg("联系电话不能为空")
            return;
        }
        if (!(/^1(3|4|5|6|7|8|9)\d{9}$/.test($("#phone").val()))) {
            layer.msg("联系电话格式不对");
            return;
        }
        if ($("#address").val() == "") {
            layer.msg("商家地址不能为空")
            return;
        }
        if ($("#account").val() == "") {
            layer.msg("账户不能为空")
            return;
        }
        if ($("#passWord").val() == "") {
            layer.msg("密码不能为空")
            return;
        }

        <#--var url="";-->
        <#--if(param!=""){-->
        <#--    url=param;-->
        <#--}else{-->
        <#--    url='${user.url}';-->
        <#--}-->
        var duo = "";
        if(duoImage != ""){
            duo = duoImage;
        }else{
            duo="";
        }



        var formDate = {
            // account: $("#account").val(),
            passWord: $("#passWord").val(),
            nameOfMerchant: $("#nameOfMerchant").val(),
            merchantContact: $("#merchantContact").val(),
            phone: $("#phone").val(),
            address: $("#address").val(),
            // url: url,
            duo:duo,
            id:$("#id").val()
        }
        // alert(JSON.stringify(formDate))

        $.ajax({
            type: "POST",
            contentType: "application/json;charset=UTF-8",
            url: "${base}/user/updateById",
            data: JSON.stringify(formDate),
            beforeSend: function () {
                loading("数据提交中，请稍后......");
            },
            success: function (data) {
                if (data.code === 200) {
                    layer.msg(data.msg,{icon: 1})
                    setTimeout(function () {
                        //退出系统
                        window.history.back(-1);
                        //控制浏览器不能后退
                        if(window.location.href.indexOf("${base}/user/login.html") > -1) {
                            //防止页面后退
                            history.pushState(null, null, document.URL);
                            window.addEventListener('popstate', function () {
                                history.pushState(null, null, document.URL);
                            });
                        }
                    }, 300)

                } else {
                    layer.msg(data.msg)
                }
            }
        });
    })
</script>

</body>
</html>